/*
 * AgendaView.java
 */
package GUI;

import Classes.Empresa;
import Classes.Persona;
import Filtros.Comparadores.Comparador;
import java.awt.event.WindowEvent;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.JFrame;
import PureFactoryClasses.*;
import java.awt.event.WindowAdapter;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JTable;

/**
 * The application's main frame.
 */
public class AgendaView extends FrameView {

    private TableModelContactos model = new TableModelContactos();
    private static final int TIPO = 0;
    private static final int INFO_CONTACTO = 1;

    public AgendaView(SingleFrameApplication app) {
        super(app);
        initComponents();
        this.getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        model.addColumn("Nombre/Razon Social");

        model.addColumn("Direccion");
        model.addColumn("Telefono");
        model.addColumn("E:Mail");

        model.addColumn("");
        model.addColumn("");
        contactTable.getColumnModel().getColumn(TableModelContactos.TIPO).setMaxWidth(0);
        contactTable.getColumnModel().getColumn(TableModelContactos.TIPO).setMinWidth(0);
        contactTable.getColumnModel().getColumn(TableModelContactos.TIPO).setPreferredWidth(0);
        contactTable.getTableHeader().getColumnModel().getColumn(TableModelContactos.TIPO).setMaxWidth(0);
        contactTable.getTableHeader().getColumnModel().getColumn(TableModelContactos.TIPO).setMinWidth(0);
        contactTable.getTableHeader().getColumnModel().getColumn(TableModelContactos.TIPO).setPreferredWidth(0);

        contactTable.getColumnModel().getColumn(TableModelContactos.CONTACTO).setMaxWidth(0);
        contactTable.getColumnModel().getColumn(TableModelContactos.CONTACTO).setMinWidth(0);
        contactTable.getColumnModel().getColumn(TableModelContactos.CONTACTO).setPreferredWidth(0);
        contactTable.getTableHeader().getColumnModel().getColumn(TableModelContactos.CONTACTO).setMaxWidth(0);
        contactTable.getTableHeader().getColumnModel().getColumn(TableModelContactos.CONTACTO).setMinWidth(0);
        contactTable.getTableHeader().getColumnModel().getColumn(TableModelContactos.CONTACTO).setPreferredWidth(0);

        this.contactTable = new JTable(model);

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });

        //Cargamos la Tabla
        this.loadContactTable();

        //Esto arregla el molesto problema de que la ventana aparece chiquita. (MJ)
        getFrame().addWindowListener(new WindowAdapter() {

            @Override
            public void windowOpened(WindowEvent we) {
                super.windowOpened(we);
                we.getWindow().setSize(we.getWindow().getPreferredSize());
            }
        });

        actualizarListaCategorias();
    }

    public final synchronized void actualizarListaCategorias() {
        cmbRubros.removeAllItems();

        ArrayList<String> listaCategorias = ApController.getInstance().listaDeCategorias();

        for (Iterator<String> it = listaCategorias.iterator(); it.hasNext();) {
            String categoria = it.next();
            cmbRubros.addItem(categoria);
        }
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = AgendaApp.getApplication().getMainFrame();
            aboutBox = new AgendaAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        AgendaApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        cbVerPersonas = new javax.swing.JCheckBox();
        cbVerEmpresas = new javax.swing.JCheckBox();
        cbFiltrarEmpresasPorRubro = new javax.swing.JCheckBox();
        cmbRubros = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        txtBusqueda = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        contactTable = new javax.swing.JTable();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        jMenu1 = new javax.swing.JMenu();
        nuevaPersonaItem = new javax.swing.JMenuItem();
        nuevaEmpresaItem = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setMinimumSize(new java.awt.Dimension(728, 629));
        mainPanel.setName("mainPanel"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(GUI.AgendaApp.class).getContext().getResourceMap(AgendaView.class);
        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        jPanel1.add(jLabel1);

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setName("jPanel2"); // NOI18N

        cbVerPersonas.setText(resourceMap.getString("cbVerPersonas.text")); // NOI18N
        cbVerPersonas.setName("cbVerPersonas"); // NOI18N
        cbVerPersonas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cambiaElFiltro(evt);
            }
        });

        cbVerEmpresas.setText(resourceMap.getString("cbVerEmpresas.text")); // NOI18N
        cbVerEmpresas.setName("cbVerEmpresas"); // NOI18N
        cbVerEmpresas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cambiaElFiltro(evt);
            }
        });

        cbFiltrarEmpresasPorRubro.setText(resourceMap.getString("cbFiltrarEmpresasRubro.text")); // NOI18N
        cbFiltrarEmpresasPorRubro.setName("cbFiltrarEmpresasRubro"); // NOI18N
        cbFiltrarEmpresasPorRubro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cambiaElFiltro(evt);
            }
        });

        cmbRubros.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbRubros.setName("cmbRubros"); // NOI18N
        cmbRubros.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbRubrosActionPerformed(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        txtBusqueda.setText(resourceMap.getString("txtBuscar.text")); // NOI18N
        txtBusqueda.setName("txtBuscar"); // NOI18N
        txtBusqueda.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtBusquedaKeyReleased(evt);
            }
        });

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbVerEmpresas)
                    .addComponent(cbVerPersonas)
                    .addComponent(cbFiltrarEmpresasPorRubro))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmbRubros, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(193, 193, 193)
                        .addComponent(jLabel2))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)))
                .addGap(77, 77, 77))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(cbVerPersonas)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cbVerEmpresas)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbFiltrarEmpresasPorRubro)
                            .addComponent(cmbRubros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)
                            .addComponent(txtBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1))))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        contactTable.setModel(model);
        contactTable.setName("contactTable"); // NOI18N
        contactTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                contactTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(contactTable);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 704, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 728, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 424, Short.MAX_VALUE))
        );

        menuBar.setMinimumSize(new java.awt.Dimension(82, 21));
        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N

        nuevaPersonaItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
        nuevaPersonaItem.setText(resourceMap.getString("nuevaPersonaItem.text")); // NOI18N
        nuevaPersonaItem.setName("nuevaPersonaItem"); // NOI18N
        nuevaPersonaItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nuevaPersonaItemActionPerformed(evt);
            }
        });
        jMenu1.add(nuevaPersonaItem);

        nuevaEmpresaItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
        nuevaEmpresaItem.setText(resourceMap.getString("nuevaEmpresaItem.text")); // NOI18N
        nuevaEmpresaItem.setName("nuevaEmpresaItem"); // NOI18N
        nuevaEmpresaItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nuevaEmpresaItemActionPerformed(evt);
            }
        });
        jMenu1.add(nuevaEmpresaItem);

        fileMenu.add(jMenu1);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(GUI.AgendaApp.class).getContext().getActionMap(AgendaView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 728, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 544, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void actualizarVista() {
        loadContactTable();
    }

    public final synchronized void loadContactTable() {
        Comparador filtro = null;

        if (cbVerEmpresas.isSelected()) {
            filtro = PureFactoryClasses.FiltrosPracticosFactory.EsEmpresa();
        }
        if (cbVerPersonas.isSelected()) {
            filtro = PureFactoryClasses.FiltrosPracticosFactory.JuntarOR(filtro, PureFactoryClasses.FiltrosPracticosFactory.EsPersona());
        }
        if (cbFiltrarEmpresasPorRubro.isSelected()) {
            filtro = PureFactoryClasses.FiltrosPracticosFactory.JuntarOR(
                    filtro,
                    PureFactoryClasses.FiltrosPracticosFactory.JuntarAND(
                    FiltrosPracticosFactory.EsEmpresa(),
                    FiltrosPracticosFactory.FiltrarPorCategoria(
                    cmbRubros.getSelectedItem().toString())));
        }

        filtro = FiltrosPracticosFactory.JuntarAND(filtro,
                FiltrosPracticosFactory.FiltrarTexto(".*" + txtBusqueda.getText() + ".*"));

        loadContactTableByFilter(filtro);
        //actualizarListaCategorias();
    }

    private synchronized void loadContactTableByFilter(Comparador filtro) {
        ApController apController = ApController.getInstance();

        ArrayList<ArrayList<Object>> listaContactos = apController.cargarTablaContactos(filtro);

        // Vaciamos la lista.
        model.setNumRows(0);

        for (int i = 0; i < listaContactos.size(); i++) {
            ArrayList<Object> info = listaContactos.get(i);
            if (info.get(TIPO) == ApController.EMPRESA) {
                model.addEmpresa((Empresa) info.get(INFO_CONTACTO));
            } else {
                model.addPersona((Persona) info.get(INFO_CONTACTO));
            }
        }
    }

    private void nuevaPersonaItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nuevaPersonaItemActionPerformed
        newContactoPersonaForm personasFrm = new newContactoPersonaForm(this, true);
        personasFrm.setVisible(true);
    }//GEN-LAST:event_nuevaPersonaItemActionPerformed

    private void nuevaEmpresaItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nuevaEmpresaItemActionPerformed
        newContactoEmpresaForm frmEmpresa = new newContactoEmpresaForm(this, true);
        frmEmpresa.setVisible(true);
    }//GEN-LAST:event_nuevaEmpresaItemActionPerformed

    private void contactTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_contactTableMouseClicked
        if (evt.getClickCount() == 2) {
            int i = contactTable.rowAtPoint(evt.getPoint());
            String tipo = (String) model.getValueAt(i, TableModelContactos.TIPO);
            if (tipo.equals(TableModelContactos.PERSONA)) {
                newContactoPersonaForm frmContacto = new newContactoPersonaForm(this,
                        true, (Persona) model.getValueAt(i, TableModelContactos.CONTACTO));
                frmContacto.setVisible(true);
            } else {
                newContactoEmpresaForm frmEmpresa = new newContactoEmpresaForm(this, true,
                        (Empresa) model.getValueAt(i, TableModelContactos.CONTACTO));
                frmEmpresa.setVisible(true);
            }
        }
    }//GEN-LAST:event_contactTableMouseClicked

    private void cmbRubrosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbRubrosActionPerformed
        actualizarVista();
    }//GEN-LAST:event_cmbRubrosActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        actualizarVista();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void cambiaElFiltro(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cambiaElFiltro
        actualizarVista();
    }//GEN-LAST:event_cambiaElFiltro

    private void txtBusquedaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtBusquedaKeyReleased
        actualizarVista();
    }//GEN-LAST:event_txtBusquedaKeyReleased
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox cbFiltrarEmpresasPorRubro;
    private javax.swing.JCheckBox cbVerEmpresas;
    private javax.swing.JCheckBox cbVerPersonas;
    private javax.swing.JComboBox cmbRubros;
    private javax.swing.JTable contactTable;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem nuevaEmpresaItem;
    private javax.swing.JMenuItem nuevaPersonaItem;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JTextField txtBusqueda;
    // End of variables declaration//GEN-END:variables
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;
}
